<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('店铺加油订单缩略列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 select-table table-striped">
            <form id="petrol-desc-list-form">
                <input type="hidden" name="productId" th:value="${productId}">
                <input type="hidden" name="payTimeBegin" th:value="${beginTime}">
                <input type="hidden" name="orderStatus" value="3">
                <input type="hidden" name="payTimeEnd" th:value="${endTime}">
                <div class="select-list">
                    <ul>
                        <li>
                            <p style="width: 110px">油枪号： </p>
                            <select name="productAttrId" th:with="productAttrList=${productAttrList}">
                                <option value="">全部</option>
                                <option th:each="attr:${productAttrList}" th:value="${attr.id}"
                                        th:text="${attr.attrName}"></option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                        </li>
                    </ul>
                </div>
            </form>
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    const prefix = ctx + "back/shopOrder";
    const payWayDict = [[${@dict.getType('pay_way')}]];

    $(function () {
        var options = {
            url: prefix + "/searchPetrolList",
            modalName: "会员加油订单",
            sortName: "payTime",
            sortOrder: "desc",
            height: 540,
            footerStyle: footerStyle,
            showSearch: true,
            showFooter: true,
            showColumns: false,
            columns: [
                {
                    field: 'payTime',
                    title: '支付时间',
                    sortable: true,
                    footerFormatter: function (value) {
                        return "本页数据汇总：" ;
                    },
                },
                {
                    field: 'productName',
                    title: '油品',
                    sortable: true
                },
                {
                    field: 'productAttrName',
                    title: '油枪号',
                    sortable: true
                },
                {
                    field: 'productUnitPrice',
                    title: '单价',
                },
                {
                    field: 'productQuantity',
                    title: '数量（升)',
                    footerFormatter: function (value) {
                        var sumAmount = 0;
                        for (var i in value) {
                            sumAmount += parseFloat(value[i].productQuantity);
                        }
                        return sumAmount.toFixed(2);
                    },
                    sortable: true
                },
                {
                    field: 'orderCost',
                    title: '应付金额（元)',
                    footerFormatter: function (value) {
                        var sumAmount = 0;
                        for (var i in value) {
                            sumAmount += parseFloat(value[i].orderCost);
                        }
                        return sumAmount.toFixed(2);
                    },
                    sortable: true
                },
                {
                    field: 'payCost',
                    title: '实付金额(元)',
                    footerFormatter: function (value) {
                        var sumAmount = 0;
                        for (var i in value) {
                            sumAmount += parseFloat(value[i].payCost);
                        }
                        return sumAmount.toFixed(2);
                    },
                    sortable: true
                },
                {
                    field: 'discountAmount',
                    title: '优惠金额(元)',
                    footerFormatter: function (value) {
                        var sumAmount = 0;
                        for (var i in value) {
                            sumAmount += parseFloat(value[i].discountAmount);
                        }
                        return sumAmount.toFixed(2);
                    },
                    sortable: true
                },
                {
                    field: 'phone',
                    title: '用户手机号',
                    sortable: true
                },
                {
                    field: 'payWay',
                    title: '支付方式',
                    visible: false,
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(payWayDict, value);
                    }
                }]
        };
        $.table.init(options);
    });

    function footerStyle(column) {
        return {
            productQuantity: {
                css: {color: 'red', 'font-weight': 'bold'}
            },
            orderCost: {
                css: {color: 'red', 'font-weight': 'bold'}
            },
            payCost: {
                css: {color: 'red', 'font-weight': 'bold'}
            },
            discountAmount: {
                css: {color: 'red', 'font-weight': 'bold'}
            },
            payTime: {
                css: {color: 'red', 'font-weight': 'bold'}
            }
        }[column.field]
    }
</script>
</body>
</html>